package c.c.b.b.d;

import android.text.TextUtils;
import b.i.b.f;
import c.c.b.b.f.c;
import c.c.b.b.f.i;
import c.c.b.b.f.m;
import c.c.b.b.f.p;
import c.c.b.b.h.b;
import java.io.File;
import java.util.HashMap;
import java.util.Map;

/* compiled from: FileRequest */
public class e extends c<File> {
    public c.c.b.b.f.p.a<File> A;
    public File x;
    public File y;
    public final Object z = new Object();

    /* compiled from: FileRequest */
    public interface a extends c.c.b.b.f.p.a<File> {
        void a(long j, long j2);
    }

    public e(String str, String str2, c.c.b.b.f.p.a<File> aVar) {
        super(str2, aVar);
        this.A = aVar;
        this.x = new File(str);
        this.y = new File(c.b.a.a.a.D(str, ".tmp"));
        try {
            File file = this.x;
            if (!(file == null || file.getParentFile() == null || this.x.getParentFile().exists())) {
                this.x.getParentFile().mkdirs();
            }
        } catch (Throwable unused) {
        }
        setRetryPolicy(new i(25000, 1, 1.0f));
        setShouldCache(false);
    }

    public p<File> a(m mVar) {
        if (isCanceled()) {
            k();
            return new p(new c.c.b.b.h.a("Request was Canceled!"));
        } else if (!this.y.canRead() || this.y.length() <= 0) {
            k();
            return new p(new c.c.b.b.h.a("Download temporary file was invalid!"));
        } else if (this.y.renameTo(this.x)) {
            return new p(null, f.f(mVar));
        } else {
            k();
            return new p(new c.c.b.b.h.a("Can't rename the download temporary file!"));
        }
    }

    public void cancel() {
        super.cancel();
        synchronized (this.z) {
            this.A = null;
        }
    }

    public Map<String, String> getHeaders() throws b {
        HashMap hashMap = new HashMap();
        StringBuilder g = c.b.a.a.a.g("bytes=");
        g.append(this.y.length());
        g.append("-");
        hashMap.put("Range", g.toString());
        hashMap.put("Accept-Encoding", "identity");
        return hashMap;
    }

    public c.c getPriority() {
        return c.c.LOW;
    }

    public final String j(c.c.b.b.f.b bVar, String str) {
        if (!(bVar == null || bVar.a() == null || bVar.a().isEmpty())) {
            for (c.c.b.b.f.a aVar : bVar.a()) {
                if (aVar != null && TextUtils.equals(aVar.a, str)) {
                    return aVar.b;
                }
            }
        }
        return null;
    }

    /* JADX WARNING: Missing exception handler attribute for start block: B:2:0x0005 */
    /* JADX WARNING: Failed to process nested try/catch */
    public final void k() {
        /*
        r1 = this;
        r0 = r1.x;	 Catch:{ all -> 0x0005 }
        r0.delete();	 Catch:{ all -> 0x0005 }
    L_0x0005:
        r0 = r1.x;	 Catch:{ all -> 0x000a }
        r0.delete();	 Catch:{ all -> 0x000a }
    L_0x000a:
        return;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.c.b.b.d.e.k():void");
    }

    public void a(p<File> pVar) {
        c.c.b.b.f.p.a aVar;
        synchronized (this.z) {
            aVar = this.A;
        }
        if (aVar != null) {
            aVar.a(new p(this.x, pVar.b));
        }
    }

    public void a(long j, long j2) {
        c.c.b.b.f.p.a aVar;
        synchronized (this.z) {
            aVar = this.A;
        }
        if (aVar instanceof a) {
            ((a) aVar).a(j, j2);
        }
    }
}
